﻿cmake_minimum_required(VERSION 3.12.4)

if(NOT CMAKE_VERSION VERSION_LESS 3.0)
    cmake_policy(SET CMP0048 NEW)
endif()

project(HelloWorldExample)

# Find requirements

if(NOT OpenSSL_FOUND)
    set(OPENSSL_ROOT_DIR "C:\\Programs\\OpenSSL-Win64")
    add_library(OpenSSL STATIC IMPORTED )
    set_target_properties(OpenSSL PROPERTIES IMPORTED_LOCATION
    ${OPENSSL_ROOT_DIR}/lib/openssl.lib
    )
    # find_package(OpenSSL )
endif()


if(NOT fastcdr_FOUND)
    find_package(fastcdr REQUIRED)
endif()

if(NOT fastrtps_FOUND)
    find_package(fastrtps REQUIRED)
endif()

# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
        CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
    if(SUPPORTS_CXX11)
        add_compile_options(-std=c++11)
    else()
        message(FATAL_ERROR "Compiler doesn't support C++11")
    endif()
endif()

file(GLOB_RECURSE ${PROJECT_NAME}_SOURCES_CXX "src/*.cxx")

file(GLOB_RECURSE ${PROJECT_NAME}_SOURCES_CPP "src/*.cpp")

file(GLOB_RECURSE ${PROJECT_NAME}_SOURCES_IDL "src/*.idl")
# message(STATUS "${PROJECT_NAME}_SOURCES_IDL = ${${PROJECT_NAME}_SOURCES_IDL}")

# if(${PROJECT_NAME}_SOURCES_IDL)
# 	set(${PROJECT_NAME}_GENERATED_SOURCE_DIR ${PROJECT_SOURCE_DIR}/generated)
# 	if(EXISTS ${${PROJECT_NAME}_GENERATED_SOURCE_DIR})
# 		message(STATUS "${PROJECT_NAME}_GENERATED_SOURCE_DIR = ${${PROJECT_NAME}_GENERATED_SOURCE_DIR} exist.")
# 	else()
# 		message(STATUS "${PROJECT_NAME}_GENERATED_SOURCE_DIR = ${${PROJECT_NAME}_GENERATED_SOURCE_DIR} does not exist.")
# 		file(MAKE_DIRECTORY ${${PROJECT_NAME}_GENERATED_SOURCE_DIR})
# 		message(STATUS "mkdir ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}.")
# 	endif()
# 	foreach(file ${${PROJECT_NAME}_SOURCES_IDL})
# 		get_filename_component(name ${file} NAME_WE)
# 		get_filename_component(directory ${file} DIRECTORY)
# 		set(${name}_GENERATED_HEADER ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}.h)
# 		set(${name}_GENERATED_SOURCE ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}.cxx)
# 		set(${name}_GENERATED_PUBSUBTYPES_HEADER ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}PubSubTypes.h)
# 		set(${name}_GENERATED_PUBSUBTYPES_SOURCE ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}PubSubTypes.cxx)
# 		set(${name}_GENERATED_CDRAUX_HEADER ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}CdrAux.hpp)
# 		set(${name}_GENERATED_CDRAUX_SOURCE ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/${name}CdrAux.ipp)
# 		message(STATUS "file = ${file}")
# 		message(STATUS "name = ${name}")
# 		message(STATUS "directory = ${directory}")
# 		message(STATUS "${name}_GENERATED_HEADER = ${${name}_GENERATED_HEADER}")
# 		message(STATUS "${name}_GENERATED_SOURCE = ${${name}_GENERATED_SOURCE}")		
# 		list(APPEND ${PROJECT_NAME}_GENERATED_HEADER ${${name}_GENERATED_HEADER})
# 		list(APPEND ${PROJECT_NAME}_GENERATED_PUBSUBTYPES_HEADER ${${name}_GENERATED_PUBSUBTYPES_HEADER})
# 		list(APPEND ${PROJECT_NAME}_GENERATED_CDRAUX_HEADER ${${name}_GENERATED_CDRAUX_HEADER})
# 		list(APPEND ${PROJECT_NAME}_GENERATED_SOURCE ${${name}_GENERATED_SOURCE})
# 		list(APPEND ${PROJECT_NAME}_GENERATED_PUBSUBTYPES_SOURCE ${${name}_GENERATED_PUBSUBTYPES_SOURCE})
# 		list(APPEND ${PROJECT_NAME}_GENERATED_CDRAUX_SOURCE ${${name}_GENERATED_CDRAUX_SOURCE})
# 	endforeach()
# 	message(STATUS "${PROJECT_NAME}_GENERATED_SOURCE = ${${PROJECT_NAME}_GENERATED_SOURCE}")
# 	
# # 			${${name}_GENERATED_SOURCE}
# # 			${${name}_GENERATED_HEADER}
# # 			${name}_GENERATED_PUBSUBTYPES_HEADER
# # 			${name}_GENERATED_PUBSUBTYPES_SOURCE
# # 			${name}_GENERATED_CDRAUX_HEADER
# # 			${name}_GENERATED_CDRAUX_SOURCE
# 
# 	message(STATUS "fastddsgen ${${PROJECT_NAME}_SOURCES_IDL} -d ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}")
# 	add_custom_target(${PROJECT_NAME}_idl
# 			ALL echo fastddsgen ${${PROJECT_NAME}_SOURCES_IDL} -d ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}
# 			WORKING_DIRECTORY ${${PROJECT_NAME}_GENERATED_SOURCE_DIR}/src
# 			DEPENDS ${PROJECT_NAME}_SOURCES_IDL
# 			)
# endif()


# foreach(file ${${PROJECT_NAME}_SOURCES_CPP})
# 	message(STATUS "file = ${file}")
# 	get_filename_component(FILENAME ${file} NAME_WE)
# 	message(STATUS "FILENAME = ${FILENAME}")
# 	add_executable(${PROJECT_NAME}_${FILENAME} 
# 		${file}
# 		${${PROJECT_NAME}_GENERATED_SOURCE}
# 		)
# 	target_link_libraries(${PROJECT_NAME}_${FILENAME} fastrtps fastcdr OpenSSL)
# 	target_include_directories(${PROJECT_NAME}_${FILENAME} PUBLIC ${${PROJECT_NAME}_GENERATED_SOURCE_DIR})
# endforeach()

# add_executable(DDSHelloFishRosSubscribe src/HelloFishRosSubscribe.cpp ${DDS_HelloFishRos_SOURCES_CXX})
# target_link_libraries(DDSHelloFishRosSubscribe fastrtps fastcdr)


include_directories(${PROJECT_SOURCE_DIR}/include)

# add_executable(cdds 
#     src/main.cpp
# 	${${PROJECT_NAME}_SOURCES_CXX})

# target_link_libraries(cdds fastrtps fastcdr OpenSSL)


add_executable(fastdds 
     src/old.cpp
)

target_link_libraries(fastdds fastrtps fastcdr OpenSSL)
